package com.hl.card.modular.packBack.controller;

import com.hl.card.common.controller.BaseController;
import com.hl.card.common.persistence.dao.JoinRebateTypeMapper;
import com.hl.card.common.persistence.model.JoinRebateType;
import com.hl.card.core.log.LogObjectHolder;
import com.hl.card.core.support.BeanKit;
import com.hl.card.modular.packBack.service.JoinRebateTypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/joinRebateType")
public class JoinRebateTypeController  extends BaseController {

    @Resource
    private JoinRebateTypeService joinRebateTypeService;


    private String PREFIX = "/packback/joinRebateType/";

    @Resource(name = "joinRebateTypeMapper")
    private JoinRebateTypeMapper joinRebateTypeMapper;

    /**
     *  主页
     */
    @RequestMapping("")
    public String index(){
        return PREFIX+"joinRebateType.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping(value = "/joinRebateType_add")
    public Object joinRebateTypeAdd(){
        return PREFIX+"joinRebateType_add.html";
    }

    /**
     * 跳转到修改销售利润管理
     */
    @RequestMapping(value = "/joinRebateType_update/{joinRebateTypeId}")
    public Object joinRebateUpdate(@PathVariable Integer joinRebateTypeId, Model model){
        JoinRebateType joinRebateType = joinRebateTypeService.selectById(joinRebateTypeId);
        Map<String, Object> joinRebatemap = BeanKit.beanToMap(joinRebateType);
        model.addAttribute("joinRebateType",joinRebatemap);
        LogObjectHolder.me().set(joinRebateType);
        return PREFIX+"joinRebateType_edit.html";
    }


    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        List<Map<String, Object>> list= joinRebateTypeService.selectList();
        System.out.println(list);
        return list;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ResponseBody
    public Object del(Integer id){
        joinRebateTypeService.delete(id);
        return super.SUCCESS_TIP;
    }
    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Object update(@Valid JoinRebateType joinRebateType){
        joinRebateTypeService.update(joinRebateType);
        return PREFIX+"joinRebate.html";
    }
    /**
     * 添加
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(JoinRebateType joinRebateType){
        JoinRebateType temp = joinRebateTypeMapper.selectByCode(joinRebateType.getCode());
        if(temp == null) {
            joinRebateTypeService.save(joinRebateType);
            return super.SUCCESS_TIP;
        }else{

            return super.FailuerTip("业务代码不能重复");
        }
    }

















}
